Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
@babel/plugin-transform-optional-chaining
Advanced tools
Transform optional chaining operators into a series of nil checks
The @babel/plugin-transform-optional-chaining package is a Babel plugin that allows developers to use the optional chaining syntax in JavaScript. Optional chaining is a feature that enables developers to read the value of a property located deep within a chain of connected objects without having to check that each reference in the chain is valid. The plugin transforms optional chaining syntax into a form that can be understood by JavaScript engines that do not support this feature natively.
Optional Property Access
This feature allows safe access to nested object properties. If any reference is nullish (null or undefined), it returns undefined instead of throwing an error.
const obj = { a: { b: { c: 1 } } };
const value = obj?.a?.b?.c;
Optional Method Calls
This feature enables calling a method that may not exist. If the method is not available, it returns undefined instead of throwing an error.
const obj = { a: { b: { c: () => 'Hello' } } };
const greeting = obj?.a?.b?.c?.();
Optional Bracket Notation
This feature allows the use of optional chaining with bracket notation, which is useful when accessing properties with keys that are not valid identifiers.
const obj = { a: { b: { 'c': 1 } } };
const value = obj?.a?.['b']?.['c'];
This package provides a way to access properties of objects using dot notation, similar to optional chaining. However, it does not support the optional chaining syntax and requires manual checks for nullish values.
Lodash's get function allows safe access to object properties, similar to optional chaining. It's a part of the Lodash utility library and requires passing the object path as a string or array, unlike the native-like syntax that optional chaining provides.
Transform optional chaining operators into a series of nil checks
See our website @babel/plugin-transform-optional-chaining for more information.
Using npm:
npm install --save-dev @babel/plugin-transform-optional-chaining
or using yarn:
yarn add @babel/plugin-transform-optional-chaining --dev
v7.24.8 (2024-07-11)
babel-parser
declare
(@liuxingbaoyu)babel-generator
in
in for
heads (@nicolo-ribaudo)await using
(@nicolo-ribaudo)babel-parser
using
declarations (@H0onnn).value: undefined
to regexp literals (@liuxingbaoyu)babel-types
ObjectTypeInternalSlot
visitor keys (@nicolo-ribaudo)babel-plugin-transform-typescript
export import x =
(@liuxingbaoyu)babel-generator
async
in for await
(@nicolo-ribaudo)babel-traverse
Scope.globals
multiple times (@liuxingbaoyu)FAQs
Transform optional chaining operators into a series of nil checks
The npm package @babel/plugin-transform-optional-chaining receives a total of 14,741,832 weekly downloads. As such, @babel/plugin-transform-optional-chaining popularity was classified as popular.
We found that @babel/plugin-transform-optional-chaining demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.